package com.gxitsky.common.utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

/**
 * @author duhao
 * @version 1.0
 * @date 2020/11/4 11:47
 */
public class JsonUtil {
    /**
     * 从json数组中找到参数value
     * "extras": [
     * {
     * "value": "7565",
     * "key": "ServiceId"
     * },
     * {
     * "value": "7565",
     * "key": "TenantId"
     * }
     * ]
     *
     * @return
     * @author 杜浩
     * @date 2020/11/4 11:44
     */
    public static String findValueFromJsonArray(JSONArray extras, String key) {
        if (EmptyUtil.isNotEmpty(extras)) {
            for (Object extra : extras) {
                JSONObject extraJson = (JSONObject) extra;
                if (extraJson.getString("Key").equals(key)) {
                    return extraJson.getString("Value");
                }
            }
        }
        return null;
    }
}
